package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/5/6 9:53
 * @since v1.0
 */
@Getter
public enum BirthdayTypeEnum {
    /**
     * 公历
     */
    BIRTHDAY(0, "enum.birthdayType.text.birthday", 0),
    /**
     * 农历
     */
    LUNAR_BIRTHDAY(1, "enum.birthdayType.text.lunar_birthday", 0);

    /**
     * 下拉存到库中值
     */
    private Integer value;

    /**
     * 下拉显示值
     */
    private String text;

    /**
     * isOther
     */
    private int isOther;

    BirthdayTypeEnum(Integer value, String text, int isOther) {
        this.value = value;
        this.text = text;
        this.isOther = isOther;
    }

    public static BirthdayTypeEnum getByValue(Integer value) {
        for (BirthdayTypeEnum birthdayTypeEnum : values()) {
            if (Objects.equals(value, birthdayTypeEnum.getValue())) {
                return birthdayTypeEnum;
            }
        }
        return BirthdayTypeEnum.BIRTHDAY;
    }

    public static BirthdayTypeEnum getByText(String text) {
        for (BirthdayTypeEnum birthdayTypeEnum : values()) {
            if (Objects.equals(text, birthdayTypeEnum.getText())) {
                return birthdayTypeEnum;
            }
        }
        return BirthdayTypeEnum.BIRTHDAY;
    }

    public String getText() {
        return I18nMessageUtil.getMessage(text);
    }

}
